package com.sk.controller;


import com.sk.dto.WxLogin2Dto;
import com.sk.entity.vo.AppletUserVo;
import com.sk.entity.vo.WeiXinLoginVo;
import com.sk.exception.WechatLoginException;
import com.sk.res.CommonResponseDto;
import com.sk.service.IAppletUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 小程序用户信息表
 * @author jiaok
 * @since 2024-04-24
 */
@RestController
@RequestMapping("/applet-user")
public class AppletUserController {

    @Resource
    private IAppletUserService iAppletUserService;

    @ApiOperation("微信登录接口")
    @PostMapping({"weiXinLogin"})
    public CommonResponseDto weiXinLogin(@RequestBody WeiXinLoginVo weiXinLoginReq) {

        try {
            WxLogin2Dto appletUserDto =  iAppletUserService.weiXinLogin(weiXinLoginReq);
            return CommonResponseDto.success(appletUserDto);
        }catch (WechatLoginException e){
            return CommonResponseDto.error(e.getCode(),e.getMessage());
        }catch (Exception e) {
            throw e;
        }
    }


    @ApiOperation("新增用户")
    @PostMapping({"saveAppletUser"})
    public CommonResponseDto saveAppletUser(@RequestBody AppletUserVo appletUserVo) {
        try {
            return iAppletUserService.saveAppletUser(appletUserVo);
        }catch (WechatLoginException e){
            return CommonResponseDto.error(e.getCode(),e.getMessage());
        }catch (Exception e) {
            throw e;
        }
    }






}
